﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenComposite.HumanActivity.Contracts;
using OpenComposite.HumanActivity.Data;
using System.ServiceModel;
using OpenComposite.Base.Collections;

namespace OpenComposite.HumanActivity.Services
{
	[ServiceBehavior(
		ConcurrencyMode = ConcurrencyMode.Multiple,
		InstanceContextMode = InstanceContextMode.Single,
		Namespace = "http://www.theopencomposite.com/internal")]
	public class HumanActivityDataService : IHumanActivityDataService
	{
		#region IHumanActivityDataService Members

		public LogInData LogIn(string username, string password, int orgid, int languageid, string orgname, Guid applicationId)
		{
			try {
				return Global.DataAccess.LogIn(username, password, orgid, languageid, orgname, applicationId);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("LogIn", ex);
			}
		}

		public bool LogOut(LogInData userdata, Guid applicationId)
		{
			try {
				return Global.DataAccess.LogOut(userdata, applicationId);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("LogOut", ex);
			}
		}

		public List<ActivityItem> GetActivityInbox(int userId)
		{
			try {
				return Global.DataAccess.GetActivityInbox(userId);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetActivityInbox", ex);
			}
		}

		public BindingListEx<ActivityItem> GetAdminActivityInbox(string processName, string activityName,
			DateTime createDateFrom, DateTime createDateTo, ActivityStatus[] status)
		{
			try {
				return Global.DataAccess.GetActivityInbox(processName, activityName, createDateFrom, createDateTo, status);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetAdminActivityInbox", ex);
			}
		}
		public List<string> GetAdminProcessNames()
		{
			try {
				return Global.DataAccess.GetAdminProcessNames();
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetAdminProcessNames", ex);
			}
		}
		public List<string> GetAdminActivityNames(string process)
		{
			try {
				return Global.DataAccess.GetAdminActivityNames(process);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetAdminActivityNames", ex);
			}
		}
		//public void SetActivityStatus(string action, int activityId)
		//{
		//    try {
		//        Global.DataAccess.SetActivityStatus(action, activityId);
		//    } catch ( Exception ex ) {
		//        throw Global.CreateAndLogGenericFault("SetActivityStatus", ex);
		//    }
		//}
		public string GetHumanActivityUrl(int activityId)
		{
			try {
				return Global.DataAccess.GetHumanActivityUrl(activityId);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetHumanActivityUrl", ex);
			}

		}

		public List<Country> GetCountries()
		{
			return new List<Country>(new Country[] {
				new Country() { LCID = 1031, CountryName = "German - Standard" },
				new Country() { LCID = 1033, CountryName = "English - United States" },
				new Country() { LCID = 1034, CountryName = "Spanish - Standard" },
				new Country() { LCID = 1036, CountryName = "French - Standard" },
				new Country() { LCID = 1040, CountryName = "Italian - Standard" },
				new Country() { LCID = 1041, CountryName = "Japanese" },
				new Country() { LCID = 1046, CountryName = "Portuguese - Brazil" },
				new Country() { LCID = 2057, CountryName = "English - United Kingdom" },
				new Country() { LCID = 2058, CountryName = "Spanish - Mexico" },
				new Country() { LCID = 2070, CountryName = "Portuguese - Standard" }
			});
		}

		public Delegation GetDelegation(string p, string p_2)
		{
			throw Global.CreateAndLogGenericFault("GetDelegation", new NotImplementedException());
		}

		public List<Delegation> GetDelegations(LogInData userdata)
		{
			throw Global.CreateAndLogGenericFault("GetDelegations", new NotImplementedException());
		}

		public bool DeleteDelegation(Delegation delegation)
		{
			throw Global.CreateAndLogGenericFault("DeleteDelegation", new NotImplementedException());
		}

		public void SetDelegation(Delegation delegation)
		{
			throw Global.CreateAndLogGenericFault("SetDelegation", new NotImplementedException());
		}

		public List<Language> GetLanguages()
		{
			try {
				return Global.DataAccess.GetLanguages();
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetLanguages", ex);
			}
		}

		public List<TimeZoneItem> GetTimeZones()
		{
			try {
				List<TimeZoneItem> timezones = new List<TimeZoneItem>();
				foreach ( var tmzone in TimeZoneInfo.GetSystemTimeZones() ) {
					TimeZoneItem tzi = new TimeZoneItem()
					{
						TimeZoneID = tmzone.Id,
						TimeZoneName = tmzone.DisplayName
					};
					timezones.Add(tzi);
				}
				return timezones;
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetTimeZones", ex);
			}
		}

		public UserPreferences GetUserPreferences(LogInData userdata)
		{
			try {
				return Global.DataAccess.GetUserPreferences(userdata);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetUserPreferences", ex);
			}
		}

		public bool SetUserPreferences(LogInData userdata, UserPreferences userpreferences)
		{
			try {
				return Global.DataAccess.SetUserPreferences(userdata, userpreferences);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("SetUserPreferences", ex);
			}
		}

		public PersonalUserData GetPersonalUserData(LogInData userdata)
		{
			try {
				return Global.DataAccess.GetPersonalUserData(userdata);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("GetPersonalUserData", ex);
			}
		}

		public bool SetPersonalUserData(LogInData userdata, PersonalUserData data)
		{
			try {
				return Global.DataAccess.SetPersonalUserData(userdata, data);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("SetPersonalUserData", ex);
			}
		}

		public bool UpdateUserPassword(LogInData userdata, string passwordOld, string passwordNew)
		{
			try {
				return Global.DataAccess.UpdateUserPassword(userdata, passwordOld, passwordNew);
			} catch ( Exception ex ) {
				throw Global.CreateAndLogGenericFault("UpdateUserPassword", ex);
			}
		}


		#endregion

	}
}
